<?php echo $this->render('/public/header'); ?>
    <script src="/statics/utils/common.js"></script>
    <script src="/statics/utils/computeMoney.js"></script>
    <style type="text/css">
        .container.box {
            padding:20px;
        }

        #my-title {
            font-size: 16px;
            font-weight: bold;
            line-height: 32px;
            padding-right: 20px;
            float: left;
        }

        .search {
            margin: 30px 0;
        }

        .search .el-input {
            width: 180px;
            margin-right: 15px;
        }
        .search .el-input--suffix .el-input__inner{
            margin-bottom: 10px;
        }
        .search .el-input__prefix, .el-input__suffix{
            top: -4px;
        }

        .el-pagination {
            margin-top: 30px;
        }

        .el-form-item {
            width: 50%;
            float: left;
        }

        .el-form-item.full {
            width: 100%;
        }

        .press_price_table {
            width: 100%;
            background: #f4f4f5;
        }

        .press_price_table tr td {
            text-align: center;
        }

        .press_price_table tr td button {
            width: 100%;
        }
        .el-button+.el-button{margin:5px;}
        .cell button{margin:5px;}
        .el-dialog{
            margin-top:6vh!important;
            width: 80%;
        }
        .label-required .el-form-item__label::after{
            content : '*';
            color:red;
            margin-left: 5px;
        }
        .add-long-input .el-form-item__content .el-autocomplete{
            width:100%;
        }
        .addData-dialog::-webkit-scrollbar{
            display: none;
            position: relative;
        }
        .consignment .el-dialog{
            width: 50%;
        }
        .flex{
            display: flex;
            align-items: center;
        }
        input::-webkit-outer-spin-button,input::-webkit-inner-spin-button{
            -webkit-appearance: none !important;
        }
        input[type="number"]{-moz-appearance:textfield;}
        .el-input.is-disabled .el-input__inner{
            color: #000;
        }
        .el-select-dropdown__item.selected{
            color: #000;
        }
        .el-dialog__body{
            padding: 30px 40px;
        }
		.el-timeline{
		  height: 200px;
		  overflow-y: auto;
		  padding-top: 5px;
		}
        .el-button--text{color: #606266;}
    </style>
    <div class="container box">
        <div id="app">
            <el-row>
                <h1 id="my-title">寄件申请列表</h1>
                <el-button type="primary" size="small" v-if="isSaleMan" @click="postData">申请寄件</el-button>
            </el-row>
            <el-dialog
                class="addData-dialog"
                title="申请寄件表格"
                :visible.sync="applyLogisticsDialogForm"
                ref="addData_dialog" @open="applyDialogFormOpen()"
                @closed="applyDialogFormClose()"
                :close-on-click-modal="false"
                :lock-scroll="false">
                <el-form :model="addData" v-loading="addDataLoading" element-loading-text="正在提交中,请稍后...">
                    <el-tabs type="card" v-model="tabscard">
                        <el-tab-pane label="货物重量" name="first">
                            <el-form-item label="长" :label-width="formLabelWidth" :class="[addData.pack_type==0?label_required:'']" style="width:33%;">
                                <el-input v-model="addData.long" :disabled="applyLogisticsDialogFormState==-2" >
                                    <template slot="append">cm</template>
                                </el-input>
                            </el-form-item>
                            <el-form-item label="宽" :label-width="formLabelWidth" :class="[addData.pack_type==0?label_required:'']" style="width:33%;">
                                <el-input v-model="addData.width" :disabled="applyLogisticsDialogFormState==-2">
                                    <template slot="append">cm</template>
                                </el-input>
                            </el-form-item>
                            <el-form-item label="高" :label-width="formLabelWidth" :class="[addData.pack_type==0?label_required:'']" style="width:33%;">
                                <el-input v-model="addData.height" :disabled="applyLogisticsDialogFormState==-2">
                                    <template slot="append">cm</template>
                                </el-input>
                            </el-form-item>
                            <el-form-item label="体积重" :label-width="formLabelWidth" style="width:33%;">
                                <el-input v-model="addData.weight" :disabled="true">
                                    <template slot="append">KG</template>
                                </el-input>
                            </el-form-item>
                            <el-form-item label="货物实重" :label-width="formLabelWidth" class="label-required" style="width:33%;">
                                <el-input v-model="addData.real_weight"  :disabled="applyLogisticsDialogFormState==-2"  >
                                    <template slot="append">KG</template>
                                </el-input>
                            </el-form-item>
                            <el-form-item label="计重" :label-width="formLabelWidth" style="width:33%;">
                                <el-input v-model="addData.press_weight"   :disabled="true">
                                    <template slot="append">KG</template>
                                </el-input>
                            </el-form-item>
                        </el-tab-pane>
                    </el-tabs>
                    <el-tabs type="card" v-model="tabscard">
                        <el-tab-pane label="寄件信息" name="first">
                            <el-form-item label="客户名称" :label-width="formLabelWidth" class="label-required add-long-input" style="width:33%;">
                                <el-select v-model="addData.customer_name" style="width: 100%;"  filterable @change="handleSelectCustomer" @focus="querySearchCustomer('',1)" :filter-method="getrealCustomer" :disabled="applyLogisticsDialogFormState==-2"  placeholder="请选择">
                                    <el-option
                                            v-for="item in searchCustomerList"
                                            :key="item.id"
                                            :label="item.customer_name"
                                            :value="item">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="客户编号" :label-width="formLabelWidth" class="label-required" style="width:33%;">
                                <el-input v-model="addData.customer_number" :disabled="true"></el-input>
                            </el-form-item>
                            <el-form-item label="收件人姓名" :label-width="formLabelWidth" class="label-required" style="width:33%;">
                                <el-input v-model="addData.press_name"  :disabled="applyLogisticsDialogFormState==-2"></el-input>
                            </el-form-item>
                            <el-form-item label="收件人国家" :label-width="formLabelWidth" style="width:33%;" class="label-required add-long-input">
                                <el-select v-model="addData.region_name" style="width: 100%;" filterable @change="handleSelectCountry" @focus="remakeCountry" :filter-method="getrealCountry" :disabled="applyLogisticsDialogFormState==-2"  placeholder="请选择">
                                    <el-option
                                            v-for="item in searchCountryList"
                                            :key="item.id"
                                            :label="item.value"
                                            :value="item">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="收件人地区" :label-width="formLabelWidth"  style="width:33%;" class="label-required">
                                <el-input v-model="addData.province_name"  :disabled="applyLogisticsDialogFormState==-2" placeholder="省份/州" style="width:49%;"></el-input>
                                <el-input v-model="addData.city_name"  :disabled="applyLogisticsDialogFormState==-2" placeholder="城市" style="width:49%;"></el-input>
                            </el-form-item>
                            <el-form-item label="收件人电话" :label-width="formLabelWidth" class="label-required" style="width:33%;">
                                <el-input v-model="addData.press_tel" :disabled="applyLogisticsDialogFormState==-2"  >
                                    <template slot="prepend">{{ addData.numberCode?'+'+addData.numberCode+'-':'' }}</template>
                                </el-input>
                            </el-form-item>
                            <el-form-item label="详细地址" :label-width="formLabelWidth" style="width:66%;" class="label-required">
                                <el-input v-model="addData.press_addr" :disabled="applyLogisticsDialogFormState==-2" ></el-input>
                            </el-form-item>
                            <el-form-item label="邮编" :label-width="formLabelWidth" style="width:33%;" class="label-required">
                                <el-input v-model="addData.post_code" :disabled="applyLogisticsDialogFormState==-2"    style="width:80%;"></el-input>
                            </el-form-item>
                            <el-form-item label="备注"  :label-width="formLabelWidth" style="width:33%;">
                                <el-input
                                type="textarea"
                                :autosize="{ minRows: 2, maxRows: 4}"
                                :disabled="applyLogisticsDialogFormState==-2"
                                placeholder="请输入相关备注"
                                v-model="addData.comment">
                                </el-input>
                            </el-form-item>
                            <el-form-item label="邮件收件人" :label-width="formLabelWidth" class="label-required add-long-input" style="width:33%;">
                                <el-select v-model="addData.email_getter_name" style="width: 100%;" filterable @change="handleSelectEmailGetter" :disabled="applyLogisticsDialogFormState==-2" @focus="handleGetEmailGetterByCustomerId()"  placeholder="请选择">
									<!--:label="(item.customer_name2==null?item.customer_name:item.customer_name2)+'('+item.email+')'"-->
                                    <el-option
                                            v-for="item in email_getter_array"
                                            :key="item.id"
                                            :label="(item.customer_name)+'('+item.email+')'"
                                            :value="item">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="邮箱" :label-width="formLabelWidth"  style="width:33%;">
                            <el-input v-model="addData.email_getter_email" :disabled="true" placeholder="暂无邮箱"></el-input>
                            </el-form-item>
                        </el-tab-pane>
                    </el-tabs>
                    <el-tabs type="card" v-model="tabscard">
                        <el-tab-pane label="选择快递" name="first">
                            <el-form-item style="width:33%;">
                                    <el-tooltip placement="top">
                                        <div slot="content">1、费用仅供参考，具体费用以寄出后快递提供价格为准<br/>
                                            2、参考费用仅包含 官方折扣价+旺季附加费+燃油附加费
                                        </div>
                                        <el-input :value="addData.forecast_price_list.fedex" :disabled="true">
                                            <template slot="prepend">Fedex</template>
                                            <template slot="append"><el-radio v-model="addData.express_id" :disabled="applyLogisticsDialogFormState==-2 || !addData.forecast_price_list.fedex" label="fedex">选择</el-radio></template>
                                        </el-input>
                                    </el-tooltip>
                            </el-form-item>
                            <el-form-item style="width:33%;box-sizing: border-box;padding:0 10px;">
                                <el-tooltip placement="top">
                                    <div slot="content">1、费用仅供参考，具体费用以寄出后快递提供价格为准<br/>
                                        2、参考费用仅包含 官方折扣价+燃油附加费
                                    </div>
                                    <el-input :value="addData.forecast_price_list.dhl" :disabled="true">
                                        <template slot="prepend">DHL</template>
                                        <template slot="append"><el-radio v-model="addData.express_id" :disabled="applyLogisticsDialogFormState==-2 || !addData.forecast_price_list.dhl" label="dhl">选择</el-radio></template>
                                    </el-input>
                                </el-tooltip>
                            </el-form-item>
                            <el-form-item style="width:33%;box-sizing: border-box;padding:0 10px;box-sizing: border-box;padding:0 10px;">
                                <el-tooltip placement="top">
                                    <div slot="content">1、费用仅供参考，具体费用以寄出后快递提供价格为准<br/>
                                        2、参考费用仅包含 官方折扣价+燃油附加费
                                    </div>
                                    <el-input :value="addData.forecast_price_list.ups_red" :disabled="true">
                                        <template slot="prepend">UPS【红】</template>
                                        <template slot="append"><el-radio v-model="addData.express_id" :disabled="applyLogisticsDialogFormState==-2 || !addData.forecast_price_list.ups_red" label="ups_red">选择</el-radio></template>
                                    </el-input>
                                </el-tooltip>
                            </el-form-item>
                            <el-form-item style="width:33%;">
                                <el-tooltip placement="top">
                                    <div slot="content">1、费用仅供参考，具体费用以寄出后快递提供价格为准<br/>
                                        2、参考费用仅包含 官方折扣价+燃油附加费
                                    </div>
                                    <el-input :value="addData.forecast_price_list.ups_blue" :disabled="true">
                                        <template slot="prepend">UPS【蓝】</template>
                                        <template slot="append"><el-radio v-model="addData.express_id" :disabled="applyLogisticsDialogFormState==-2 || !addData.forecast_price_list.ups_blue" label="ups_blue">选择</el-radio></template>
                                    </el-input>
                                </el-tooltip>
                            </el-form-item>

                            <el-form-item label="物流公司" :label-width="formLabelWidth" class="label-required" style="width:33%;box-sizing: border-box;padding:0 10px 0 0;">
                                <el-input v-model="addData.express_company_show"  :disabled="true"></el-input>
                            </el-form-item>
                            <el-form-item label="包装方式" :label-width="formLabelWidth" style="width:33%;box-sizing: border-box;padding:0 10px;" class="label-required">
                                <el-select v-model="addData.pack_type" :disabled="applyLogisticsDialogFormState==-2" placeholder="请选择包装方式">
                                    <!-- <el-option label="请选择" value=""></el-option> -->
                                    <el-option label="自备包装（非官方包材）" value="0"></el-option>
                                    <el-option label="官方快递袋" value="1"></el-option>
                                    <el-option label="官方文件封" value="2"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="目地关税" :label-width="formLabelWidth" class="label-required" style="width:33%;">
                                <el-select v-model="addData.tax_man" :disabled="applyLogisticsDialogFormState==-2" placeholder="请选择">
                                    <el-option label="客户承担" value="0"></el-option>
                                    <el-option label="我方承担" value="1"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="是否保险" :label-width="formLabelWidth" class="label-required" style="width:33%;">
                                <el-select v-model="addData.is_safe" :disabled="applyLogisticsDialogFormState==-2" placeholder="请选择">
                                    <el-option label="是" value="0"></el-option>
                                    <el-option label="否" value="1"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="额外附加费" :label-width="formLabelWidth"  style="width:33%;">
                            <el-input v-model="addData.extra_charge" :disabled="applyLogisticsDialogFormState==-2"    style="width:80%;"></el-input>
                            </el-form-item>
                        </el-tab-pane>
                    </el-tabs>
                    <el-tabs type="card" v-model="tabscardGoods" style="position: relative;overflow: auto">
                        <el-tab-pane label="产品列表"  name="first" >
                            <el-table
                                    :data="addData.goods_data"
                                    border
                                    style="width: 100%">
                                <el-table-column
                                        prop="goods_name"
                                        label="产品名称"
                                        width="180">
                                </el-table-column>
                                <el-table-column
                                        prop="english_name"
                                        label="英文名称"
                                        width="180">
                                </el-table-column>
                                <el-table-column
                                        prop="goods_number"
                                        label="产品数量"
                                >
                                </el-table-column>
                                <el-table-column
                                        prop="goods_price"
                                        label="单个产品申报价值">
                                </el-table-column>
                                <el-table-column
                                        prop="goods_unit_name"
                                        label="单位"
                                        width="100">
                                </el-table-column>
                                <el-table-column
                                        prop="goods_bianma"
                                        label="HS海关编码">
                                </el-table-column>
                                <el-table-column
                                        fixed="right"
                                        label="操作"
                                        width="80">
                                    <template slot-scope="scope">
                                        <el-button @click="delGoods(scope.row,scope.$index)" :disabled="applyLogisticsDialogFormState==-2" type="text" size="small">删除
                                        </el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <div v-if="applyLogisticsDialogFormState!=-2">
                                <el-form :model="new_goods_data">
                                    <el-row>
                                        <el-col :span="5">
                                            <el-form-item label-width="0" style="width: 100%;">
                                                <el-input v-model="new_goods_data.goods_name" placeholder="中文产品名称" @blur="searchHsCode">
                                                </el-input>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="5">
                                            <el-form-item label-width="0" style="width: 100%;">
                                                <el-input v-model="new_goods_data.english_name" placeholder="英文产品名称" >
                                                </el-input>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="3">
                                            <el-form-item label-width="0" style="width: 100%;">
                                                <el-input  v-model="new_goods_data.goods_number" placeholder="产品数量">
                                                </el-input>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="5">
                                            <el-form-item label-width="0" style="width: 100%;">
                                                <el-input placeholder="申报价格" v-model="new_goods_data.goods_price" class="input-with-select">
                                                    <template slot="prepend">{{goods_unit_list[new_goods_data.goods_unit]}}</template>
                                                    <el-select v-model="new_goods_data.goods_unit" style="width: 100px;" slot="append" placeholder="单位">
                                                        <el-option label="人民币" value="0"></el-option>
                                                        <el-option label="美元" value="1"></el-option>
                                                        <el-option label="欧元" value="2"></el-option>
                                                    </el-select>
                                                </el-input>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="4">
                                            <el-form-item label-width="0" style="width: 100%;">
                                                <el-autocomplete
                                                        class="inline-input"
                                                        v-model="new_goods_data.goods_bianma"
                                                        :fetch-suggestions="querySearchHsCode"
                                                        placeholder="HS海关编码"
                                                        @select="handleSelectHsCode">
                                                </el-autocomplete>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="2">
                                            <el-form-item label-width="0" style="width: 100%;">
                                                <el-button type="primary" size="small"  @click="addGoods()">添加产品</el-button>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </div>
                    </el-tabs>
                </el-form>
                <div slot="footer" class="dialog-footer" v-if="tabscardGoods == 'first'">
                    <el-button @click="applyLogisticsDialogForm = false" v-if="applyLogisticsDialogFormState!==-2">取 消</el-button>
                    <el-button type="primary" @click="postLogisticsForm" :loading="addDataLoading" v-if="applyLogisticsDialogFormState!==-2">确 定</el-button>
                    <el-button type="primary"  v-if="applyLogisticsDialogFormState==-2" @click="applyLogisticsDialogForm=false">关 闭</el-button>
                </div>
            </el-dialog>

            <el-row class="search">
            <el-col :lg="4" :xl="5">
                收件人国家/地区：
                <el-select v-model="searchData.country" filterable @change="searchCountry" clearable @focus="remakeCountry" :filter-method="getrealCountry"    placeholder="请选择">
                    <el-option
                        v-for="item in searchCountryList"
                        :key="item.id"
                        :label="item.value"
                        :value="item">
                    </el-option>
                </el-select>
            </el-col>
            <el-col :span="4">
                物流公司：
                <el-select v-model="searchData.express_company" placeholder="请选择">
                    <el-option label="全部" value="-1"></el-option>
                    <el-option label="Fedex" value="0"></el-option>
                    <el-option label="DHL" value="1"></el-option>
                    <el-option label="UPS【红】" value="2"></el-option>
                    <el-option label="UPS【蓝】" value="3"></el-option>
                </el-select>
            </el-col>
            <el-col :lg="4" :xl="5">
                等待申请状态：
                <el-select v-model="searchData.status" placeholder="请选择">
                    <el-option label="全部" value="-1"></el-option>
                    <el-option label="等待发货" value="0"></el-option>
                    <el-option label="申请驳回" value="1"></el-option>
                    <el-option label="发货中" value="2"></el-option>
                    <el-option label="发货完成" value="3"></el-option>
                </el-select>
            </el-col>
            <el-col :span="4">
                客户名称：
                <el-select v-model="searchData.customer_name " clearable class="no-blue"  filterable @change="handleSelectCustomerForm" @focus="querySearchCustomer('',0)" :filter-method="getrealCustomer2"   placeholder="请选择">
                    <el-option
                        v-for="item in searchMoreCustomerList"
                        :key="item.id"
                        :label="item.customer_name"
                        :value="item">
                    </el-option>
                </el-select>
            </el-col>
            <el-col :span="4">
                客户编号：
                <el-input v-model="searchData.customer_code" placeholder="客户编号">
                </el-input>
            </el-col>
            </el-row>
            <el-row class="search">
                <el-col :span="4">
                    快递单号：
                    <el-input v-model="searchData.express_number" placeholder="快递单号">
                    </el-input>
                </el-col>
                <el-col :span="6">
                    日期：
                        <el-date-picker
                            style="position:relative;"
                            v-model="value1"
                            type="daterange"
                            @change='dateChange'
                            range-separator="-"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            :picker-options="pickerOptions"
                            :default-time="['00:00:00', '23:59:59']">
                        </el-date-picker>
                </el-col>
                <el-col :span="2">
                    <el-button type="primary" size="small" @click="search">搜索</el-button>
                </el-col>
            </el-row>
            <el-table :data="table_data">
                <el-table-column prop="report_number" label="寄件申请单号" width="120"></el-table-column>
                <el-table-column prop="customer_name" label="客户名称" width="120"></el-table-column>
                <el-table-column prop="status_name" label="寄件申请状态" width="100"></el-table-column>
                <el-table-column prop="region_name" label="收件人国家/地区" width="130"></el-table-column>
                <el-table-column prop="express_name" label="物流公司" width="90"></el-table-column>
                <el-table-column prop="press_weight" label="计重" width="80"></el-table-column>
                <el-table-column prop="press_price" label="预估费用" width="90"></el-table-column>
                <el-table-column prop="real_price" label="发件预估费用" width="100"></el-table-column>
                <el-table-column label="实际费用" width="120">
                    <template slot-scope="scope" >
                        <el-input v-if="(job_number==141  && scope.row.status == 3) ||(job_number==158  && scope.row.status == 3)" v-model="scope.row.finance_price" placeholder="实际费用" @input="((val)=>{handleInputRealFee(val,scope.$index)})" @change='((val)=>{handleChangeRealFee(val,scope.row.id)})'></el-input>
                        <div v-else-if="scope.row.status == 3">
                        {{scope.row.finance_price}}
                        </div>
                    </template>
                </el-table-column>
				<el-table-column prop="express_number" label="运单号" width="145"></el-table-column>
                <el-table-column width="180" >
					  <template slot="header" slot-scope="scope">
						<el-tooltip placement="top">
						    <div slot="content">
								※发货员填完运单号后，第二天才会更新物流信息，已存在物流信息的更新间隔为一小时<br/>
								pending     -- 查询中：新增包裹正在查询中，请等待<br/>
								notfound    -- 查询不到：包裹信息目前查询不到<br/>
								※transit   -- 运输途中：物流商已揽件，包裹正被发往目的地<br/>
								pickup      -- 到达待取：包裹正在派送中，或到达当地收发点<br/>
								※delivered -- 成功签收：包裹已被成功投递<br/>
								expired	    -- 运输过久：包裹在很长时间内都未投递成功。快递包裹超过30天、邮政包裹超过60天未投递成功，该查询会被识别为此状态<br/>
								undelivered	-- 投递失败：快递员投递失败（通常会留有通知并再次尝试投递）<br/>
								exception   -- 可能异常：包裹退回、包裹丢失、清关失败等异常情况
							</div>
						  <el-button>最新物流信息</el-button>
						</el-tooltip>

					  </template>
                    <template slot-scope="scope" >
						<el-popover  placement="right"  width="500"  trigger="click">
						<div v-for="(info_data,key,index) in scope.row.express_info">
					　　	<div v-if="(key == 'data')">
								<template v-for="(info_detail,key,index) in info_data">
									<div v-if="(key == 'origin_info')">
										<template v-for="(trackinfo,key,index) in info_detail">
											<div v-if="(key == 'trackinfo')">
											  <el-timeline>
												<el-timeline-item
												  v-for="(info_list, index) in trackinfo"
												  :key="index"
												  :timestamp="info_list.Date">
												  {{info_list.StatusDescription}}
												</el-timeline-item>
											  </el-timeline>
											</div>
										</template>
									</div>
								</template>
							</div>
						</div>
						<el-button slot="reference" type="text" label="物流信息" >{{scope.row.express_code}}
							<div v-for="(info_detail,key,index) in scope.row.express_info" class="cell">
								<div v-if="(key == 'data')">
									<template  v-for="(info_last,key,index) in info_detail" >
										<p v-if="(key == 'lastEvent')">{{info_last}}</p>
									</template>
								</div>
						　　</div>
						</el-button>
						</el-popover>
                    </template>
				</el-table-column>
                <el-table-column prop="finish_time" label="发货完成时间" width="145"></el-table-column>
                <el-table-column prop="creator" label="业务员" width="60"></el-table-column>
                <el-table-column prop="consigner" label="操作员" width="60"></el-table-column>
                <el-table-column label="操作" >
                    <template slot-scope="scope">
                        <el-button
                                size="mini"
                                @click="handleEdit(scope.$index, scope.row , -2)">查看
                        </el-button>
                        <el-button v-if="(job_number==141  && scope.row.status == 2) ||(job_number==158  && scope.row.status == 2)"
                                size="mini" type="success"
                                @click="handleEdit(scope.$index, scope.row , 2)">发货
                        </el-button>
                        <el-button v-if="(job_number==141  && scope.row.status == 0) ||(job_number==158  && scope.row.status == 0)"
                                size="mini" type="warning"
                                @click="handleEdit(scope.$index, scope.row , 0)">审核
                        </el-button>
                        <el-button v-if="(job_number==141  && scope.row.status == 2) ||(job_number==158  && scope.row.status == 2)"
                                size="mini" type="danger"
                                @click="handleEdit(scope.$index, scope.row , -1)">驳回
                        </el-button>
                        <el-button v-if="scope.row.status == 1 && isSaleMan && scope.row.creator_job_number==job_number"
                                size="mini" type="primary"
                                @click="handleEdit(scope.$index, scope.row , 1)">编辑
                        </el-button>
                        <el-button v-if="scope.row.status == 3 && isSaleMan && scope.row.creator_job_number==job_number"
                                   size="mini"
                                   type="success"
                                   @click="handleEdit(scope.$index, scope.row , 3)">再来一单
                        </el-button>
                        <el-button v-if="scope.row.status == 1 && isSaleMan && scope.row.creator_job_number==job_number"
                                   size="mini"
                                   type="danger"
                                   @click="handelDelete(scope.row.id)">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="page"
              :page-sizes="[10, 20, 50, 100]"
              :page-size="10"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
            </el-pagination>
            <el-dialog title="发货" class="addData-dialog consignment" :visible.sync="dialogFormConsignment">
                <el-form :model="Consignment">
                    <el-form-item label="快递费用" :label-width="formLabelWidth" class="label-required">
                        <el-input v-model="Consignment.real_price" ></el-input>
                    </el-form-item>
                    <el-form-item label="快递单号" :label-width="formLabelWidth" class="label-required">
                        <el-input v-model="Consignment.express_number" ></el-input>
                    </el-form-item>
                    <el-form-item label="业务员备注" :label-width="formLabelWidth" style="width:50%;">
                        <el-input
                        type="textarea"
                        :autosize="{ minRows: 2, maxRows: 4}"
                        placeholder="请输入相关备注"
                        v-model="Consignment.comment">
                        </el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormConsignment = false">取 消</el-button>
                    <el-button type="primary" :disabled="is_can_click" @click="dialogFormConsignmentPost">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>

    <script>
        var first_in=0;
        new Vue({
            el: '#app',
            watch : {
                'addData.long' : {
                    handler(val) {
                        val=testInputNumber(val);
                        if(parseInt(val)>99999){
                            val=99999
                        }
                        if(val != '') {
                            this.addData.long = parseInt(val)
                        }else {
                            this.addData.long=''
                        }
                        this.computeWeight()
                    },
                    deep : true
                },
                'addData.width' : {
                    handler(val) {
                        val=testInputNumber(val);
                        if(parseInt(val)>99999){
                            val=99999
                        }
                        if(val != '') {
                            this.addData.width = parseInt(val)

                        }else {
                            this.addData.width=''
                        }
                        this.computeWeight();
                    },
                    deep : true
                },
                'addData.height' : {
                    handler(val) {
                        val=testInputNumber(val);
                        if(parseInt(val)>99999){
                            val=99999
                        }
                        if(val != '') {
                            this.addData.height = parseInt(val)

                        }else {
                            this.addData.height=''
                        }
                        this.computeWeight();
                    },
                    deep : true
                },
                'addData.weight':{
                    handler(val) {
                        if(parseInt(val)>99999){
                            this.addData.weight=99999
                        }
                        this.computePrice();

                    },
                    deep : true
                },
                'addData.press_weight':{
                    handler(val) {
                        if(parseInt(val)>99999){
                            this.addData.press_weight=99999
                        }
                    },
                    deep : true
                },
                'addData.extra_charge':{
                    handler(val) {
                        val=testFloatNumber(val,2);
                        if(parseInt(val)>99999){
                            val=99999
                        }
                        if(val != '') {
                            this.addData.extra_charge = val
                        }else {
                            this.addData.extra_charge=''
                        }
                        this.computePrice();
                    },
                    deep : true
                },
                'real_fee_rule.fee':{
                    handler(val) {
                        val=testFloatNumber(val,2);
                        if(val != '') {
                            this.real_fee_rule.fee = val
                            this.table_data[this.real_fee_rule.id].finance_price=val
                        }else {
                            this.real_fee_rule.fee=''
                            this.table_data[this.real_fee_rule.id].finance_price=''
                        }
                    },
                    deep : true
                },
                'addData.real_weight' : {
                    handler(val) {
                        val=testFloatNumber(val,2);
                        if(parseInt(val)>99999){
                            val=99999
                        }
                        if(val != '') {
                            this.addData.real_weight = val;
                        }else {
                            this.addData.real_weight=''
                        }
                        this.computeWeight();
                        this.computePrice();
                    },
                    deep : true
                },
                'addData.country_id' : {
                    handler(val) {
                        this.computePrice();
                    },
                    deep : true
                },
                'addData.express_id' : {
                    handler(val) {
                        if(this.addData.express_id=='ups_red'){
                            this.addData.express_company_show='UPS【红】'
                            this.addData.express_company=2
                        }else if(this.addData.express_id=='ups_blue'){
                            this.addData.express_company_show='UPS【蓝】'
                            this.addData.express_company=3
                        }else if(this.addData.express_id=='fedex'){
                            this.addData.express_company_show = 'Fedex'
                            this.addData.express_company=0
                        }else if(this.addData.express_id=='dhl'){
                            this.addData.express_company_show = 'DHL'
                            this.addData.express_company=1
                        }else{
                            this.addData.express_company_show = ''
                            this.addData.express_company=''
                        }
                    },
                    deep : true
                },
                'addData.pack_type' : {
                    handler(val) {
                        this.computeWeight();
                        this.computePrice();
                    },
                    deep : true
                },
                'addData.post_code':{
                    handler(val) {
                         val=testInputNumberAndA_z(val)
                         this.addData.post_code=val
                    },
                    deep : true
                },
                'addData.press_tel':{
                    handler(val) {
                        val=testInputNumber(val)
                        this.addData.press_tel=val
                    },
                    deep : true
                },
                'new_goods_data.goods_number':{
                    handler(val) {
                        val=testInputNumber(val)
                        this.new_goods_data.goods_number=val
                    },
                    deep : true
                },
                'new_goods_data.goods_bianma':{
                    handler(val) {
                        val=testFloatNumber(val,2);
                        this.new_goods_data.goods_bianma=val
                    },
                    deep : true
                },
                'new_goods_data.goods_price':{
                    handler(val) {
                        val=testFloatNumber(val,2);
                        this.new_goods_data.goods_price=val
                    },
                    deep : true
                },
                dialogFormConsignment(val) {
                    if(val == false) {
                        this.Consignment.real_price = '';
                        this.Consignment.express_number = '';
                        this.Consignment.comment='';
                    }
                },
                'Consignment.real_price':{
                    handler(val) {
                        val=testFloatNumber(val,2);
                        this.Consignment.real_price=val
                    },
                    deep : true
                },
                'Consignment.express_number':{
                    handler(val) {
                        val=testInputNumberAndA_z(val);
                        this.Consignment.number=val
                    },
                    deep : true
                }
            },
            data() {
                return {
                    hscodelist : [],
                    tabscard : 'first',
                    tabscardGoods : 'first',
                    job_number:<?php echo $job_number;?>,
                    isSaleMan:<?php echo in_array($role, $temp_permition_limit) ? 'true' : 'false'; ?>,
                    role:<?php echo $role;?>,
                    editLogisticsButton : true,
                    Consignment : {
                        id : '',
                        real_price : '',
                        express_number : '',
                        comment:''
                    },
                    dialogFormConsignment : false,
                    label_required:'label-required',
                    applyLogisticsDialogEditGoodsForm : false,
                    applyLogisticsDialogForm: false,
                    new_goods_data : {
                        goods_name : '',
                        english_name:'',
                        goods_number : '',
                        goods_price : '',
                        goods_bianma : '',
                        goods_unit : ''
                    },
                    express : [
                        'Fedex','DHL','UPS【红】','UPS【蓝】'
                    ],
                    customer_list: [],
                    formLabelWidth: '98px',
                    searchData: {
                        status: '-1',
                        customer_id: '',
                        express_company: '-1',
                        customer_name : '',
                        country_id:'',
                        country:{},
                        customer_code:'',   
                        express_number:'',     
                        begin_time:'',
                        end_time:'',
                      
                    },
                    value1: '',
                    pickerOptions: {
                            shortcuts: [
                                {
                                    text:'今天',
                                    onClick(picker){
                                        let end = new Date();                      
                                        let start=new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        picker.$emit('pick',[start,end]);
                                    }
                                },
                                {
                                    text: '3天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start = new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 3);
                                        end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '本周',
                                    onClick(picker) {
                                        var nowTemp = new Date(new Date(new Date().toLocaleDateString()).getTime())//当天的0点0分0秒
                                        cTime = nowTemp.getTime(); //当前时间的毫秒时间
                                        cDay = nowTemp.getDay() || 7; //当前时间的星期几
                                        mTime = cTime - (cDay - 1) * 24 * 60 * 60 * 1000; //当前周一的毫秒时间
                                        monday = new Date(mTime); //设置周一时间对象
                                        const end = new Date();
                                        const start = monday;
                                        picker.$emit('pick', [start, end]);                                    
                                    }
                                }
                                , {
                                    text: '上周',
                                    onClick(picker) {
                                        var nowTemp = new Date(new Date(new Date().toLocaleDateString()).getTime())//当天的0点0分0秒
                                        let lastTime =new Date(new Date(new Date().toLocaleDateString()).getTime()+24*60*60*1000-1)//当天的最后一秒
                                        cTime = nowTemp.getTime(); //当前0点的毫秒时间
                                        lTime = lastTime.getTime();//当前59秒的毫秒时间
                                        cDay = nowTemp.getDay() || 7; //当前时间的星期几
                                        mTime2 = lTime - (cDay - 1) * 24 * 60 * 60 * 1000 - 24 * 3600 * 1000; //当前周一的毫秒时间结束时间
                                        mTime1 = cTime - (cDay - 1) * 24 * 60 * 60 * 1000 - 7 * 24 * 60 * 60 * 1000; //上周一的毫秒时间
                                        let end = new Date(mTime2);
                                        let start = new Date(mTime1);
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '本月',
                                    onClick(picker) {
                                        var data=new Date(new Date(new Date().toLocaleDateString()).getTime())//当天的0点0分0秒
                                        data.setDate(1);
                                        data.setHours(0);
                                        data.setSeconds(0);
                                        data.setMinutes(0);
                                        const end = new Date();
                                        const start = data;
                                        end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '上月',
                                    onClick(picker) {
                                        var data=new Date();
                                        data.setDate(1);
                                        data.setHours(0);
                                        data.setSeconds(0);
                                        data.setMinutes(0);
                                        data.setMonth(data.getMonth() - 1);
                                        var data2 = new Date();
                                        data2.setDate(1);
                                        data2.setHours(0);
                                        data2.setSeconds(0);
                                        data2.setMinutes(0);
                                        const end = data2;
                                        const start = data;
                                        end.setTime(end.getTime()-1000);
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '7天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start =new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                        end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                     
                                    }
                                }
                                , {
                                    text: '14天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start = new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 14);
                                      end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '30天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start =new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                         end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '60天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start =new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 60);
                                        end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '90天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start =new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                        end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '120天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start =new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 120);
                                        end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }]
                    },
                    goods_unit_list:[
                        '¥','$','€'
                    ],
                    status_list:[
                        '等待发货',
                         '申请驳回',
                         '发货中',
                         '发货完成'
                    ],
                    addDataLoading: false,
                    addData: {
                        op_type:0,
                        id : 0,
                        express_id : '',
                        express_company: '',
                        express_company_show:'',
                        pack_type: '',
                        long: '',
                        width: '',
                        height: '',
                        weight: '',
                        real_weight: '',
                        press_weight: '',
                        cal_weight:'',
                        forecast_price_list:{
                            fedex:'',
                            dhl:'',
                            ups_red:'',
                            ups_blue:''
                        },
                        country:'',
                        numberCode:'',
                        press_price : '',
                        extra_charge:'0',
                        customer_id : '',
                        customer_name: '',
                        customer_number: '',
                        press_name: '',
                        press_tel: '',
                        region_name : '',
                        country_id: '',
                        province_name : '',
                        city_name : '',
                        press_addr: '',
                        post_code : '',
                        goods_data: [],
                        tax_man : '0',
                        is_safe : '1',
                        ups_area:'',
                        dhl_zone:'',
                        comment:'',
                        email_getter_name:'',
                        email_getter:'',
                        email_getter_email:''
                    },
                    table_data: [],
                    page : 1,
                    limit : 10,
                    total : 0,
                    rules : {
                        country_id : [
                            ['empty','请选择顾客所在的国家/地区'],
                            ['lte',0,'']
                        ],
                        customer_name : [
                            ['empty','客户名称不能为空']
                        ],
                        customer_id : [
                            ['empty','未选择正确客户']
                        ],
                        customer_number : [
                            ['empty','未选择正确客户02']
                        ],
                        press_name : [
                            ['empty','收件人姓名不能为空']
                        ],
                        press_tel : [
                            ['empty','收件人电话不能为空']
                        ],
                        province_name : [
                            ['empty','请填写收件人地址所在的州/省份']
                        ],
                        city_name : [
                            ['empty','请填写收件人地址所在的城市']
                        ],
                        press_addr : [
                            ['empty','填写收件人的详细地址']
                        ],
                        post_code : [
                            ['empty','请填写收件人所在城市的邮编']
                        ],
                        express_id : [
                            ['empty','请选择合适的快递']
                        ],
                        pack_type : [
                            ['empty','请选择合适的包装']
                        ],
                        goods_data : [
                            ['empty_array','请增加相应的产品']
                        ],
                        tax_man : [
                            ['empty','请选择目的地关税承担方']
                        ],
                        is_safe : [
                            ['empty','请选择产品是否保险']
                        ],
                        real_weight:[
                            ['empty','请填写货物实重']
                        ],
                        email_getter:[
                            ['empty','请选择发货邮件收取人']
                        ]
                    },
                    allCountryList:[],
                    searchCountryList:[],
                    searchCustomerList:[],
                    searchMoreCustomerList:[],
                    /*控制弹窗*/
                    applyLogisticsDialogFormState:0,
                    timer:null,
                    real_fee_rule:{
                        fee:'',
                        id:''
                    },
                    email_getter_array:{},
                    is_can_click:false
                }
            },
            mounted(){
                this.getALlCountry();
                /*监听防抖*/
                this.computePrice = debounce(this.computePrice.bind(this), 300)
                this.computeWeight = debounce(this.computeWeight.bind(this), 300)
                this.querySearchCustomer=debounce(this.querySearchCustomer.bind(this), 300)
            },
            methods: {
                //日期输入框改变时
                dateChange(e){
                    if(e==null){
                        this.value1=[]
                        this.searchData.begin_time=null
                        this.searchData.end_time=null
                    }else{
                        this.searchData.begin_time=this.dateToMs(this.value1[0])
                        this.searchData.end_time=this.dateToMs(this.value1[1])
                    }          
                },
                //改为时间戳格式10位
                dateToMs(date) {
                    let result =Math.trunc(new Date(date).getTime()/1000)
                    return result;
                },
                handelDelete(id){
                    this.$confirm('是否删除该寄件申请', '提示', {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        axios.post('/api/logistics/delete-logistics',{
                            id
                        }).then(response=> {
                                if(response.data.code == 0) {
                                    this.$message({
                                        type: 'success',
                                        message: '删除成功'
                                    });
                                    this.loadData();

                                }else{
                                    this.$message({
                                        type: 'error',
                                        message: response.data.msg
                                    });
                                    this.loadData();
                                }
                            })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消'
                        });
                    });
                },
                //改变真实费用
                handleChangeRealFee(e,id){
                axios.post('/api/logistics/change-real-fee',{
                    finance_price:e,id:id
                }).then(response=> {
                        if(response.data.code == 0) {
                            this.$message({
                                type: 'success',
                                message: '修改成功'
                            });
                            this.loadData();

                        }else{
                            this.$message({
                                type: 'error',
                                message: response.data.msg
                            });
                            this.loadData();
                        }
                    })
                },
                //输入真实费用时进行数据格式化校验
                handleInputRealFee(e,index){
                    this.real_fee_rule.fee=e;
                    this.real_fee_rule.id=index;
                },
                //编辑/新增弹窗开启时回调
                applyDialogFormOpen(){
                    this.getALlCountry();
                    //重置添加产品
                    this.tabscardGoods = 'first'
                },
                //新增弹窗关闭时的回调
                applyDialogFormClose(){
                   this.applyLogisticsDialogFormState=0
                   this.reMakeData()
                },
                /*json搜索国家*/
                getrealCountry(val){
                    if (val) { //val存在
                        this.searchCountryList = this.allCountryList.filter((item) => {
                            //首字母查询
                            val=val.replace(/\s*/g,"")
                            if(val.toLowerCase()==item.value.substr(0,val.length).replace(/\s*/g,"").toLowerCase()){
                                return true
                            }
                            //模糊查询
                            // if (!!~item.value.indexOf(val) || !!~item.value.toUpperCase().indexOf(val.toUpperCase())) {
                            //     return true
                            // }
                        })
                    } else { //val为空时，还原数组
                        this.remakeCountry()
                    }
                },
                remakeCountry(){
                    this.searchCountryList=this.allCountryList
                },
                //json搜索用户
                getrealCustomer(val){
                    if (val) { //val存在
                        this.querySearchCustomer(val,1)
                    } else { //val为空时，还原数组
                        this.querySearchCustomer('',1)
                    }
                },
                //json搜索用户
                getrealCustomer2(val){
                    if (val) { //val存在
                        this.querySearchCustomer(val,0)
                    } else { //val为空时，还原数组
                        this.querySearchCustomer('',0)
                    }
                },
                remakeCustomer(){
                    this.searchCustomerList=this.allCustomerList
                },
                remakeCustomer2(){
                    this.searchMoreCustomerList=this.allMoreCustomerList
                },
                searchHsCode() {
                    axios.get('/api/logistics/searchcode',{
                        params : {
                            goods_name : this.new_goods_data.goods_name
                        }
                    }).then(response=>{
                        this.hscodelist = response.data;
                    })
                },
                postData() {
                    this.reMakeData();
                    this.addData.forecast_price_list.fedex='';
                    this.addData.forecast_price_list.dhl='';
                    this.addData.forecast_price_list.ups_red='';
                    this.addData.forecast_price_list.ups_blue='';
                    this.applyLogisticsDialogForm = true
                },
                //重置页面数据
                reMakeData(){
                    this.addData.id = 0;
                    this.addData.op_type=0;
                    this.addData.express_id = '';
                    this.addData.express_company = '';
                    this.addData.express_company_show = '';
                    this.addData.pack_type = '0';
                    this.addData.long = '';
                    this.addData.width = '';
                    this.addData.height = '';
                    this.addData.weight = '';
                    this.addData.cal_weight='';
                    this.addData.real_weight = '';
                    this.addData.press_weight = '';
                    this.addData.press_price = '';
                    this.addData.extra_charge='0';
                    this.addData.customer_id = '';
                    this.addData.customer_name = '';
                    this.addData.customer_number = '';
                    this.addData.press_name = '';
                    this.addData.press_tel = '';
                    this.addData.region_name = '';
                    this.addData.country_id = '';
                    this.addData.province_name = '';
                    this.addData.numberCode='';
                    this.addData.ups_area='';
                    this.addData.dhl_zone='';
                    this.addData.city_name = '';
                    this.addData.press_addr = '';
                    this.addData.post_code = '';
                    this.addData.goods_data = [];
                    this.addData.tax_man = '0';
                    this.addData.is_safe = '1';
                    this.addData.comment=''
                    this.addData.country=''
                    this.addData.email_getter_name=''
                    this.addData.email_getter=''
                    this.addData.email_getter_email=''
                    this.addData.data_snapshot=''
                    this.email_getter_array=[]
                    this.new_goods_data={
                        goods_name : '',
                        goods_number : '',
                        english_name:'',
                        goods_price : '',
                        goods_bianma : '',
                        goods_unit : '',
                        goods_unit_name:''
                    }
                },
                handleSizeChange(v){
                    this.limit = v;
                    this.loadData();
                },
                handleCurrentChange(v){
                    this.page = v;
                    this.loadData();
                },
                dialogFormConsignmentPost() {
                    let checkRules = this.checkFields({
                        'real_price' : [
                            ['empty' ,'运费价格不能为空']
                        ],
                        'express_number' : [
                            ['empty' ,'快递单号不能为空']
                        ]
                    },this.Consignment);

                    if(checkRules.status == false){
                        this.$message({
                            type: 'error',
                            message: checkRules.msg
                        });
                        return false;
                    }
                    this.is_can_click=true;
                    axios.post('/api/logistics/postexpress',this.Consignment).then(response=> {
                        if(response.data.code == 0) {
                             this.$message({
                                type: 'success',
                                message: response.data.msg
                              });
                             this.loadData();

                        }else{
                            this.$message({
                            type: 'error',
                            message: response.data.msg
                            });
                        }
                        this.dialogFormConsignment = false;
                        this.is_can_click=false;
                    }).catch(()=>{
                        this.is_can_click=false;
                    })

                },
                handleEdit(i , dd , status) {
                    let d = dd;
                    switch(status) {
                        case 0 : //审核
                            this.$confirm('请选择想要的操作?', '审核', {
                                distinguishCancelAndClose : true,
                                confirmButtonText: '审核通过',
                                cancelButtonText: '驳回申请',
                                type: 'success'
                            }).then(() => {
                                axios.post('/api/logistics/changestatus',{
                                    status : 2,
                                    id : d.id
                                }).then(response=> {
                                    if(response.data.code == 0) {
                                         this.$message({
                                            type: 'success',
                                            message: '审核成功!'
                                          });
                                         this.loadData();
                                    }else{
                                        this.$message({
                                        type: 'error',
                                        message: response.data.msg
                                        });
                                    }
                                })
                            }).catch(action => {
                                if(action == 'cancel') {
                                    axios.post('/api/logistics/changestatus',{
                                        status : 1,
                                        id : d.id
                                    }).then(response=> {
                                        if(response.data.code == 0) {
                                            this.$message({
                                                type: 'success',
                                                message: '驳回成功!'
                                            });
                                            this.loadData();
                                            }else{
                                                this.$message({
                                                type: 'error',
                                                message: response.data.msg
                                                });
                                            }
                                        })
                              }
                            });
                            break;
                        case 1: //编辑
                            for(let key  in d){
                                if(key=='long'||key=='width'||key=='height'){
                                    this.addData[key] = parseInt(d[key])
                                }else {
                                    this.addData[key] = d[key];
                                }
                            }
                            if(this.addData.email_getter!=''){
                                this.get_email_getter(this.addData.email_getter)
                                .then((res) => {
                                    this.addData.email_getter_email=res.data.email
                                    // this.addData.email_getter_name=(res.data.customer_name2==null?res.data.customer_name:res.data.customer_name2)
                                    this.addData.email_getter_name=(res.data.customer_name)
                                })
                                .catch((err) =>{})
                            }
                            //this.getNumberCodeById();
                            this.addData.op_type=1
                            this.applyLogisticsDialogForm = true;
                            break;
                        case 3: //再来一单
                            for(let key  in d){
                                if(key=='long'||key=='width'||key=='height'){
                                    this.addData[key] = parseInt(d[key])
                                }else {
                                    this.addData[key] = d[key];
                                }
                            }
                            if(this.addData.email_getter!=''){
                                this.get_email_getter(this.addData.email_getter)
                                .then((res) => {
                                    this.addData.email_getter_email=res.data.email
                                    // this.addData.email_getter_name=(res.data.customer_name2==null?res.data.customer_name:res.data.customer_name2)
                                    this.addData.email_getter_name=(res.data.customer_name)
                                })
                                .catch((err) =>{})
                            }
                            //this.getNumberCodeById();
                            this.addData.op_type=0
                            this.applyLogisticsDialogForm = true;
                            break;
                        case -2: //查看
                            for(let key  in d){
                                if(key=='long'||key=='width'||key=='height'){
                                    this.addData[key] = parseInt(d[key])
                                }else {
                                    this.addData[key] = d[key];
                                }
                            }
                            if(this.addData.status!=3 && this.addData.email_getter!=''){
                                this.get_email_getter(this.addData.email_getter)
                                .then((res) => {
                                    this.addData.email_getter_email=res.data.email
                                    // this.addData.email_getter_name=(res.data.customer_name2==null?res.data.customer_name:res.data.customer_name2)
                                    this.addData.email_getter_name=(res.data.customer_name)
                                })
                                .catch((err) =>{})
                            }
                            if(this.addData.status==3 && this.addData.data_snapshot!==null){
                                this.addData.customer_name=this.addData.data_snapshot.customer_info.customer_name,
                                this.addData.customer_number = this.addData.data_snapshot.customer_info.number;
                                this.addData.customer_id = this.addData.data_snapshot.customer_info.id;
                                this.addData.email_getter_email=this.addData.data_snapshot.email_getter_info.email
                                // this.addData.email_getter_name=(this.addData.data_snapshot.email_getter_info.customer_name2==null?this.addData.data_snapshot.email_getter_info.customer_name:this.addData.data_snapshot.email_getter_info.customer_name2)
                                this.addData.email_getter_name=(this.addData.data_snapshot.email_getter_info.customer_name)
                                this.addData.email_getter=this.addData.data_snapshot.email_getter_info.id
                            }
                            // this.getNumberCodeById();
                            this.editLogisticsButton = false;
                            this.applyLogisticsDialogForm = true;
                            this.applyLogisticsDialogFormState=-2
                            break;
                        case 2: //发货
                            this.Consignment.comment=d.comment
                            this.Consignment.id = d.id;
                            this.editLogisticsButton = true;
                            this.dialogFormConsignment = true;
                            break;
                        case -1 : //驳回
                            this.$confirm('此操作将驳回该寄件申请, 是否继续?', '提示', {
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                type: 'warning'
                            }).then(() => {
                                axios.post('/api/logistics/changestatus',{
                                    status : 1,
                                    id : d.id
                                }).then(response=> {
                                    if(response.data.code == 0) {
                                        this.$message({
                                            type: 'success',
                                            message: '驳回成功!'
                                        });
                                         this.loadData();
                                    }else{
                                        this.$message({
                                        type: 'error',
                                        message: response.data.msg
                                        });
                                    }
                                })
                            })
                            break;
                        default:
                            this.$message({
                                type: 'error',
                                message: '未确定的操作方式'
                            });
                            break;
                    }
                },
                search() {
                    this.loadData(1);
                },
                loadData(page) {
                    let data_page = this.page;
                    if(page != undefined) {
                        data_page = page;
                    }
                    let search=this.searchData;
                    let params={}
                    params.page = data_page;
                    params.limit = this.limit;
                    params.country_id=search.country_id==''?null:search.country_id
                    params.customer_code=search.customer_code==''?null:search.customer_code
                    params.express_company=search.express_company==-1?null:search.express_company
                    params.status=search.status==-1?null:search.status
                    params.customer_id=search.customer_id==''?null:search.customer_id
                    params.express_number=search.express_number==''?null:search.express_number
                    params.begin_time=search.begin_time==''?null:search.begin_time
                    params.end_time=search.end_time==''?null:search.end_time
                    axios.get('/api/logistics/list', {
                        params : params
                    }).then(response=> {
                        if(response.data.code==0){
                            this.table_data = response.data.data.list;
                            this.table_data.forEach(ite=>{
                                ite.express_name=this.express[ite.express_company]
                                ite.status_name=this.status_list[ite.status]
                                let country_id=ite.country_id
                            try {
                                this.allCountryList.forEach(item => {
                                    if (item.id == country_id) {
                                        ite.numberCode=item.code
                                        ite.ups_area=item.ups_area
                                        ite.dhl_zone=item.dhl_zone
                                        ite.region_name=item.value
                                            //跳出循环
                                        throw new Error("ending")
                                    }
                                })
                            } catch (e) {
                                    if (e.message == "ending") {}
                                }
                            if(ite.express_company==2){
                                ite.express_id='ups_red'
                            }else if(ite.express_company==3){
                                ite.express_id='ups_blue'
                            }else if(ite.express_company==0){
                                ite.express_id='fedex'
                            }else if(ite.express_company==1){
                                ite.express_id='dhl'
                            }else{
                                ite.express_id=''
                            }
                            ite.goods_data.forEach(item => {
                                item.goods_unit_name=this.goods_unit_list[item.goods_unit]
                            });
                                })
                            this.total = parseInt(response.data.data.total);
                        }else{
                            this.$message({
                            type: 'error',
                            message: response.data.msg
                            });
                        }
                    }).catch(error=> {
                    })
                    .then(()=>{
                        // always executed
                    });
                },
                checkFields(rules,params) {
                    let resObj = {
                        status : true,
                        msg : ''
                    };
                    Object.keys(rules).forEach(key => {
                        rules[key].map(item => {
                            if(resObj.status == true) {
                                switch(item[0]) {
                                    case 'empty':
                                        if(params[key] == ''){
                                            resObj.status = false;
                                            resObj.msg = item[1];
                                        }
                                        break;
                                    case 'number' :
                                        let r = /^[0-9]+.?[0-9]*/;
                                        if(!r.test(item[0])) {
                                            resObj.status = false;
                                            resObj.msg = item[1];
                                        }
                                        break;
                                    case 'empty_array':
                                        if(params[key].length == 0) {
                                            resObj.status = false;
                                            resObj.msg = item[1];
                                        }
                                        break;
                                    case 'lte': // <=
                                        if(params[key] <= item[1]) {
                                            resObj.status = false;
                                            resObj.msg = item[2];
                                        }
                                        break;
                                    case 'lt': // <
                                        if(params[key] < item[1]) {
                                            resObj.status = false;
                                            resObj.msg = item[2];
                                        }
                                        break;
                                    case 'gt': // >
                                        if(params[key] > item[1]) {
                                            resObj.status = false;
                                            resObj.msg = item[2];
                                        }
                                        break;
                                    case 'gte': // >=
                                        if(params[key] >= item[1]) {
                                            resObj.status = false;
                                            resObj.msg = item[2];
                                        }
                                        break;
                                    default:
                                        break;
                                }
                            }

                        });
                    });
                    return resObj;
                },
                postLogisticsForm() {
                    let checkRules = this.checkFields(this.rules,this.addData);
                    if(this.addData.pack_type == 0) {
                        if(this.addData.width == '' || this.addData.height == '' || this.addData.long == '') {
                            this.$message({
                                type: 'error',
                                message: '您选择的包装方式为自备包装，请务必填入包装的长、宽、高'
                            });
                            return false;
                        }
                    }
                    if(checkRules.status == false){
                        this.$message({
                            type: 'error',
                            message: checkRules.msg
                        });
                        return false;
                    }
                    let data=this.addData
                    data.goods_data.forEach(item=>{
                        delete item.goods_unit_name
                    })
                    let postData={
                        op_type:data.op_type,
                        id:data.id,
                        express_company:data.express_company,
                        pack_type:data.pack_type,
                        long:data.long,
                        width:data.width,
                        height:data.height,
                        weight:data.weight,
                        real_weight:data.real_weight,
                        press_weight:data.press_weight,
                        press_price:data.forecast_price_list[data.express_id],
                        extra_charge:data.extra_charge,
                        customer_id:data.customer_id,
                        press_name:data.press_name,
                        press_tel:data.press_tel,
                        country_id:data.country_id,
                        province_name:data.province_name,
                        city_name:data.city_name,
                        press_addr:data.press_addr,
                        post_code:data.post_code,
                        goods_data:data.goods_data,
                        tax_man:data.tax_man,
                        is_safe:data.is_safe,
                        forecast_price_list:data.forecast_price_list,
                        comment:data.comment,
                        email_getter:data.email_getter
                    }
                    this.addDataLoading = !this.addDataLoading;
                    axios.post('/api/logistics/add',postData).then(response=> {
                        if(response.data.code == 0) {
                            this.applyLogisticsDialogForm = false;
                            this.$message({
                              message: '申请已提交，请等待审核',
                              center: true,
                              type:'success'
                            });
                            this.loadData();
                        }else{
                            this.$message({
                              message: response.data.msg,
                              center: true,
                              type:'warning'
                            });
                        }
                        this.addDataLoading = !this.addDataLoading;
                    }).catch(() =>{
                        this.addDataLoading = !this.addDataLoading;
                    })
                },
                addGoods() {
                    let checkRules = this.checkFields({
                        goods_name : [
                            ['empty','商品名称不能为空']
                        ],
                        goods_number : [
                            ['empty','请输入产品数量']
                        ],
                        goods_price : [
                            ['empty','请输入产品的申报价格']
                        ],
                        goods_bianma : [
                            ['empty','请填写海关编码']
                        ],
                        goods_unit : [
                            ['empty','请选择价格的单位']
                        ],
                        english_name:[
                            ['empty','产品英文名称不能为空']
                        ]
                    },this.new_goods_data);
                    if(checkRules.status == false){
                        this.$message({
                            type: 'error',
                            message: checkRules.msg
                        });
                        return false;
                    }
                    // this.new_goods_data.ikey = Math.random();
                    let addGood=this.new_goods_data
                    addGood.goods_unit_name=this.goods_unit_list[addGood.goods_unit]
                    this.addData.goods_data.push(addGood);
                    this.new_goods_data={
                        goods_name : '',
                        goods_number : '',
                        english_name:'',
                        goods_price : '',
                        goods_bianma : '',
                        goods_unit : '',
                        goods_unit_name:''
                    }
                    this.tabscardGoods = 'first';
                },
                delGoods(row,index) {
                    this.addData.goods_data.splice(index,1);
                },
                querySearch(str, db) {
                },
                handleSelect(str) {
                },
                computeWeight(){
                    if(this.applyLogisticsDialogFormState==-2 || !this.applyLogisticsDialogForm){
                        return false;
                    }
                    if(this.addData.long != '' && this.addData.long != 0 &&
                        this.addData.width != '' && this.addData.width != 0 &&
                        this.addData.height != '' && this.addData.height != 0
                    ) {
                        let ceil_weight = this.addData.long * this.addData.width * this.addData.height / 5000;
                        //体积重保留一位小数
                        ceil_weight_display = parseFloat(ceil_weight.toFixed(2));
                        this.addData.weight = ceil_weight_display; //体积重
                        this.addData.cal_weight=ceil_weight;
                        let compute_weight = ceil_weight;
                        if(this.addData.real_weight != ''){
                            let real_weight=parseFloat(this.addData.real_weight)
                            if(ceil_weight > real_weight){
                                compute_weight = ceil_weight;
                            }else{
                                compute_weight = real_weight;
                            }
                        }else{
                            compute_weight = ceil_weight;
                        }
                        if (compute_weight > 20.5) {
                            var w = Math.ceil(compute_weight);
                        } else {
                            var w = Math.ceil(compute_weight);
                            if (w - compute_weight >= 0.5) {
                                w = w - 0.5;
                            }
                        }
                        this.addData.press_weight = w;
                    }else{
                        this.addData.weight = '';
                        this.addData.cal_weight='';
                        this.addData.press_weight = '';
                        if(this.addData.real_weight != '') {
                            let real_weight=parseFloat(this.addData.real_weight)
                            if (real_weight > 20.5) {
                                var w = Math.ceil(real_weight);
                            } else {
                                var w = Math.ceil(real_weight);
                                if (w - real_weight >= 0.5) {
                                    w = w - 0.5;
                                }
                            }
                            this.addData.press_weight = w;
                        }else{
                            this.addData.press_weight = '';
                        }
                    }
                },
                computePrice(){
                    //计算物流费用
                    if(this.applyLogisticsDialogFormState==-2  || !this.applyLogisticsDialogForm){
                        return false;
                    }
                    // console.log(this.addData.long,this.addData.width,this.addData.height,this.addData.real_weight,this.addData.weight,this.addData.country_id,this.addData.pack_type,this.addData.extra_charge)
                    let PriceArray= computeMoney(this.addData.long,this.addData.width,this.addData.height,this.addData.real_weight,this.addData.cal_weight,this.addData.country_id,this.addData.pack_type,this.addData.extra_charge)
                    this.addData.forecast_price_list.fedex=PriceArray.fedex
                    this.addData.forecast_price_list.dhl=PriceArray.dhl
                    this.addData.forecast_price_list.ups_red=PriceArray.ups_red
                    this.addData.forecast_price_list.ups_blue=PriceArray.ups_blue
                    let obj=this.addData.forecast_price_list
                    for(let key in obj){
                        if(obj[key]==''&&this.addData.express_id==key){
                            if(this.addData.express_id=='fedex'&&this.addData.pack_type==1 && this.addData.press_weight > 2.5){
                                this.$message({
                                type: 'error',
                                message: 'Fedex规定快递袋重量不得大于2.5kg，请选择更合适的包装方式'
                            });
                            }
                             if((this.addData.express_id=='ups_red' || this.addData.express_id=='ups_blue') && !this.addData.ups_area){
                                this.$message({
                                type: 'error',
                                message: '该地区ups物流公司未覆盖，请选择更合适的物流公司'
                            });
                             }
                             if(this.addData.express_id=='dhl' && !this.addData.dhl_zone){
                                this.$message({
                                type: 'error',
                                message: '该地区dhl物流公司未覆盖，请选择更合适的物流公司'
                            });
                             }
                            this.addData.express_id=''
                            break;
                        }
                    }
                },
                handleSelectCountry(country) {
                    this.addData.region_name=country.value
                    this.addData.country_id = country.id;
                    // //this.addData.press_tel = '+' + country.code + '-';
                    this.addData.numberCode=country.code
                    this.addData.ups_area=country.ups_area
                    this.addData.dhl_zone=country.dhl_zone
                },
                searchCountry(country){
                    this.searchData.country_id=country.id;
                },
                handleSelectHsCode(hs_code) {
                    this.new_goods_data.goods_bianma = hs_code.value;
                },
                 handleSelectCustomer(customer) {
                    // console.log(customer)
                    this.addData.customer_number = customer.number;
                    this.addData.customer_id = customer.id;
                    this.addData.customer_name = customer.customer_name;
                    this.addData.press_name = customer.customer_name;
                    if(customer.id!=0){
                         this.get_email_getters()
                            .then(res =>{

                            const email_getter = res.data.find((value)=>value.is_main == '1');
                            if(email_getter){
                                // this.addData.email_getter_name=(email_getter.customer_name2==null?email_getter.customer_name:email_getter.customer_name2)
                                this.addData.email_getter_name=(email_getter.customer_name)
                                this.addData.email_getter=email_getter.id
                                this.addData.email_getter_email=email_getter.email
                            }else {
                                // this.addData.email_getter_name=(res.data[0].customer_name2==null?res.data[0].customer_name:res.data[0].customer_name2)
                                this.addData.email_getter_name=(res.data[0].customer_name)
                                this.addData.email_getter=res.data[0].id
                                this.addData.email_getter_email=res.data[0].email
                            }
                            this.email_getter_array=res.data
                        })
                    }
                },
                get_email_getters(){
                    return http.get('/logistics/get_email_getters', {
                            params: {
                                id:this.addData.customer_id
                            }
                        })
                },
                get_email_getter(id){
                    return http.get('/logistics/get_email_getter', {
                        params: {id}
                    })
                },
                //通过客户id获取所有联系人
                handleGetEmailGetterByCustomerId(){
                        this.get_email_getters()
                        .then((res) => {
                            this.email_getter_array=res.data
                        })
                        .catch(() => {})
                },
                //选择邮件收取人
                handleSelectEmailGetter(item){
                    // this.addData.email_getter_name=item.customer_name2==null?item.customer_name:item.customer_name2
                    this.addData.email_getter_name=item.customer_name
                    this.addData.email_getter=item.id
                    this.addData.email_getter_email=item.email
                },
                handleSelectCustomerForm(customer) {
                    this.searchData.customer_id = customer.id;
                    this.searchData.customer_name=customer.customer_name
                },
                querySearchHsCode(queryString,cb) {
                    let result = this.hscodelist;
                    cb(result);
                },
                //获取所有地区
                getALlCountry() {
                    let params={}
                    axios.get('/api/logistics/regionlist', {
                        params: params
                    }).then((response)=>{
                        let list = [];
                        let country_list = response.data.data.list
                        country_list.forEach((item, key) => {
                            list.push({
                                value: item.region_english_name,
                                id: item.id,
                                code : item.country_code,
                                ups_area:item.ups_area,
                                dhl_zone:item.dhl_zone
                            });
                        })
                        this.allCountryList=list
                        this.searchCountryList=list
                        if(first_in>0){
                            return;
                        }
                        this.loadData();
                        first_in++;
                    });

                },
                getNumberCodeById(){
                    let country_id=this.addData.country_id
               try {
              this.allCountryList.forEach(item => {
                if (item.id == country_id) {
                    this.addData.numberCode=item.code
                    this.addData.ups_area=item.ups_area
                    this.addData.dhl_zone=item.dhl_zone
                        //跳出循环
                    throw new Error("ending")
                }
                  })
                } catch (e) {
                    if (e.message == "ending") {}
                }
                    if(this.addData.express_company==2){
                            this.addData.express_company_show='UPS【红】'
                            this.addData.express_id='ups_red'
                        }else if(this.addData.express_company==3){
                            this.addData.express_company_show='UPS【蓝】'
                            this.addData.express_id='ups_blue'
                        }else if(this.addData.express_company==0){
                            this.addData.express_company_show = 'Fedex'
                            this.addData.express_id='fedex'
                        }else if(this.addData.express_company==1){
                            this.addData.express_company_show = 'DHL'
                            this.addData.express_id='dhl'
                        }else{
                            this.addData.express_company_show = ''
                            this.addData.express_id=''
                        }
                },
                querySearchCustomer(customer_name, type) {
                    if(customer_name==''){
                        customer_name=null
                    }
                    axios.get('/api/logistics/customer', {
                        params: {
                            customer_name: customer_name,
                            op_type:type
                        }
                    }).then(res=> {
                        // handle success
                        let list = [];
                        if(res.data.code==0){
                        res.data.data.forEach((item, key) => {
                            list.push({
                                customer_name: item.customer_name,
                                number: item.number,
                                id: item.id
                            });
                        })
                        if(type==0){
                        this.searchMoreCustomerList=list
                        }else{
                        this.searchCustomerList=list
                        }
                    }else{
                       this.$message({
                            type: 'error',
                            message: res.data.msg
                          });
                    }
                    });
                }
            }
        })
    </script>
<?php echo $this->render('/public/footer'); ?>
